package com.oppo.action;

import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.oppo.bean.UserBean;
import com.oppo.service.impl.UserDataService;
import com.oppo.tools.MyTools;


	@WebServlet("/UserNameAction")
	public class UserNameAction extends HttpServlet {
		private static final long serialVersionUID = 1L;
		protected void service(HttpServletRequest request, HttpServletResponse response) {
			try {
				System.out.println("yyyy");
				request.setCharacterEncoding("utf-8");// 设置接收编码类型
				response.setCharacterEncoding("utf-8");// 设置发送编码数据类型
				String user_id=request.getSession().getAttribute("user_id").toString();
				String[] user_name=request.getParameterValues("name1");
				System.out.println(user_name);
				UserBean one=new UserBean();
				one.setUser_id(new Long(user_id));				
				one.setUser_name(user_name[0]);				
				int list=MyTools.getNewInstance(UserDataService.class).UpDataName(one);

				
				String strJson = JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");// 借用第三方工具将list集合转换为json字符串
				PrintWriter JOIN = response.getWriter();//响应客户端的请求
				System.out.println(list);
				JOIN.write(strJson);//将字符串发送给客户端
				JOIN.flush();
				JOIN.close();
				

			} catch (Exception e) {
				System.out.println("用户信息接收发送错误");
				e.printStackTrace();
			}
		}

	}

